const app = getApp();
const utils = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    number: '',
    email: '',
    codeUrl: ''
  }, 
  bindNumber: function(e) {
    this.setData({
      number:  e.detail.value
    })
  },
  bindEmail: function(e) {
    this.setData({
      email: e.detail.value
    })
  },

   //发送
   sendEmail: function() {
    let that = this;
    let email = that.data.email;
    let number = that.data.number;
    if (email==''){
      that.checkWrite('请输入邮箱');
      return;
    } else if (!email.match(/^[.a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/)){
      that.checkWrite('邮箱格式不正确，请重新输入');
      return;
    }
    that.setData({
      codeUrl: ''
     })  
    wx.showLoading({title: '正在发送'})
    wx.request({
      url: app.globalData.host + '/api/tool/DiningToEmail?uid=' + app.globalData.userInfo.Uid + '&number=' + number + '&email='+ email,
      success: function(res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          that.setData({
            codeUrl: res.data.Data
          })
          console.log(that.data.codeUrl)
          wx.showToast({
            title: '发送成功',
          })          
        }
      }
    })
  },
  copy: function (e) {
    let data = this.data.codeUrl;
    wx.setClipboardData({
      data: data,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
  },

  //填写判断
  checkWrite: function(str) {
    wx.showModal({
      title: '提示',
      content: str,
      showCancel: false
    })
  }
})